package com.itheima.controller.shop;

import com.itheima.pojo.Order;
import com.itheima.pojo.Result;
import com.itheima.service.OrdersService;
import com.itheima.service.ShopOrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/shopOrders")
@RestController
@Slf4j
public class ShopOrdersController {
    @Autowired
    private ShopOrdersService shopOrdersService;

    /**
     * 添加订单
     * @param order
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Order order){
        shopOrdersService.add(order);
        return  Result.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping
    public Result delete(@RequestParam Integer id){
        shopOrdersService.delete(id);
        return  Result.success();
    }

    /**
     * 商家查谁下了我的单
     * 用户查自己买的单
     * @return
     */
    //根据商家id查
    @GetMapping("/slist/{sId}")
    public Result selectSOrder( @PathVariable Integer sId){
    List<Order> orderList = shopOrdersService.selectSOrder(sId);
        return Result.success(orderList);
    }




    //根据顾客id查
    @GetMapping("/ulist/{uId}")
    public Result listClient(@PathVariable Integer uId){
     List<Order> orderList = shopOrdersService.listClient(uId);
     return  Result.success(orderList);
    }


}
